﻿<?php
	header("Content-type: text/css; charset=utf-8");
	/** Include PHPExcel */
	require_once '../lib/PHPExcel/PHPExcel/IOFactory.php';
	if (!file_exists("Data.xlsx")) {
		exit("檔案不存在!!" . PHP_EOL);
	}
	$objPHPExcel = PHPExcel_IOFactory::load("Data.xlsx");
	$SheetNo = $_GET['SheetNo'];
	//$page = $_GET['page']; // get the requested page
	//$limit = $_GET['rows']; // get how many rows we want to have into the grid
	//$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
	//$sord = $_GET['sord']; // get the direction
	// 讀取工作表(編號從 0 開始) 
	$sheet = $objPHPExcel->getSheet($SheetNo); 
	// 取得總列數 
	$highestRow = $sheet->getHighestRow(); 
	$highestColumn = $sheet->getHighestColumn();
	$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
	// 一次讀取一列 
	$result = array();
	for ($row = 2; $row <= $highestRow; $row++) {
		$temp = array();
		for ($column = 0; $column < $highestColumnIndex; $column++) { 
			$val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
			$key = "C".$column;
			$temp[] = $val;
		}
		$result[]['cell'] = $temp;
	} 
	echo "{\"rows\":".json_encode($result)."}";
?>